import Request from '@/utils/requestMain'

// 上传文件接口
export function uploadFile (data: any, progress?: (e: number) => void) {
  return Request({
    url: '/identification/api/upload/file',
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    method: 'POST',
    data,
    transformRequest: [d => {
      const formData = new FormData()
      for (const key in d) {
        formData.append(key, d[key])
      }
      return formData
    }],
    // 上传进度
    onUploadProgress: (e) => {
      const complete = e.loaded / e.total * 100 | 0
      progress && progress(complete)
    }
  })
}

// 上传文件接口(布控人脸)
export function fileRandomFid (data: any, progress?: (e: number) => void) {
  return Request({
    url: '/identification/api/upload/fileRandomFid',
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    method: 'POST',
    data,
    transformRequest: [d => {
      const formData = new FormData()
      for (const key in d) {
        formData.append(key, d[key])
      }
      return formData
    }],
    // 上传进度
    onUploadProgress: (e) => {
      const complete = e.loaded / e.total * 100 | 0
      progress && progress(complete)
    }
  })
}
